package cn.zlp.order.controller;

import cn.zlp.basic.util.AjaxResult;
import cn.zlp.basic.util.PageList;
import cn.zlp.order.domain.AdoptOrder;
import cn.zlp.order.query.AdoptOrderQuery;
import cn.zlp.order.service.IAdoptOrderService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
@RequestMapping("/adoptOrder")
public class AdoptOrderController {

    @Autowired
    private IAdoptOrderService adoptOrderService;

    /**
     * 领养订单
     * @param params
     * @param request
     * @return
     */
    @PostMapping("/submit")
    public AjaxResult submit(@RequestBody Map<String,Object> params, HttpServletRequest request){
        try{
            String payData = adoptOrderService.submit(params, request);
            return AjaxResult.me().setResultObj(payData);
        }catch (Exception e){
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMsg("下单失败！"+e.getMessage());
        }
    }

    /**
     * 查询管理员领养订单消息 - 后台系统
     * @param adoptOrderQuery - 分页参数 + 高级查询参数
     * @return 查询结果 - totals data
     */
    @ApiOperation(value = "管理员领养订单消息",notes = "")
    @PostMapping("/admin")
    public PageList<AdoptOrder> adminAdoptOrder(@RequestBody AdoptOrderQuery adoptOrderQuery, HttpServletRequest request){
        return adoptOrderService.adminAdoptOrder(adoptOrderQuery,request);
    }

    /**
     * 查询用户领养订单消息 - 前台系统
     * @param adoptOrderQuery - 分页参数 + 高级查询参数
     * @return 查询结果 - totals data
     */
    @ApiOperation(value = "用户领养订单消息",notes = "")
    @PostMapping("/user")
    public PageList<AdoptOrder> userAdoptOrder(@RequestBody AdoptOrderQuery adoptOrderQuery, HttpServletRequest request){
        return adoptOrderService.userAdoptOrder(adoptOrderQuery,request);
    }

}
